#define DEBUG
#include <cstdio>
#include <cstring>

using namespace std;

const int maxn=200000;

long long max(long long a, long long b) {
  return a>b ? a : b;
}

long long min(long long a, long long b) {
  return a<b ? a : b;
}

int main() {
  freopen("min.in", "r", stdin);
  freopen("min.out", "w", stdout);

  static int x[maxn+1];
  int n, a, b, c, d;
  scanf("%d %d %d %d %d", &n, &a, &b, &c, &d);
  for (int i=1; i<=n; i++) {
    scanf("%d", x+i);
  }

  static long long f[maxn+1];
  memset(f, 130, sizeof(f));
  f[0] = 0;
  for (int i=1; i<=n; i++) {
    long long minx=x[i];
    for (int j=i-1; j>=0; j--) {
      f[i] = max(f[i], f[j]+minx*minx*minx*a+minx*minx*b+minx*c+d);
      minx = min(minx, x[j]);
    }
  }

  printf("%lld", f[n]);

  fclose(stdin);
  fclose(stdout);
  return 0;
}
